Answer the following questions and complete the exercises in RMarkdown. Please embed all of your code and push your final work to your repository. Your final lab report should be organized, clean, and run free from errors. Remember, you must remove the # for the included code chunks to run. Be sure to add your name to the author header above. For any included plots, make sure they are clearly labeled. You are free to use any plot type that you feel best communicates the results of your analysis.
Make sure to use the formatting conventions of RMarkdown to make your report neat and clean!
library(tidyverse)
library(janitor)
library(here)
library(ggmap)
We will use two separate data sets for this homework.
The first data set represent sightings of grizzly bears (Ursos arctos) in Alaska.
The second data set is from Brandell, Ellen E (2021), Serological dataset and R code for: Patterns and processes of pathogen exposure in gray wolves across North America, Dryad, Dataset.
Load the grizzly data and evaluate its structure. As part of this step, produce a summary that provides the range of latitude and longitude so you can build an appropriate bounding box.
grizzly <- read_csv(here("lab12", "data", "bear-sightings.csv"))
## Rows: 494 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (3): bear.id, longitude, latitude
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
glimpse(grizzly)
## Rows: 494
## Columns: 3
## $ bear.id <dbl> 7, 57, 69, 75, 104, 108, 115, 116, 125, 135, 137, 162, 185, …
## $ longitude <dbl> -148.9560, -152.6228, -144.9374, -152.8485, -143.2948, -149.…
## $ latitude <dbl> 62.65822, 58.35064, 62.38227, 59.90122, 61.07311, 62.91605, …
lat <- c(55.02, 70.37)
long <- c(-131.3, -166.2)
bbox <- make_bbox(long, lat, f = 0.05)
stamen in a terrain style projection and display the map.map1 <- get_map(bbox, maptype = "terrain", source = "stamen")
## Source : http://tile.stamen.com/terrain/5/1/6.png
## Source : http://tile.stamen.com/terrain/5/2/6.png
## Source : http://tile.stamen.com/terrain/5/3/6.png
## Source : http://tile.stamen.com/terrain/5/4/6.png
## Source : http://tile.stamen.com/terrain/5/1/7.png
## Source : http://tile.stamen.com/terrain/5/2/7.png
## Source : http://tile.stamen.com/terrain/5/3/7.png
## Source : http://tile.stamen.com/terrain/5/4/7.png
## Source : http://tile.stamen.com/terrain/5/1/8.png
## Source : http://tile.stamen.com/terrain/5/2/8.png
## Source : http://tile.stamen.com/terrain/5/3/8.png
## Source : http://tile.stamen.com/terrain/5/4/8.png
## Source : http://tile.stamen.com/terrain/5/1/9.png
## Source : http://tile.stamen.com/terrain/5/2/9.png
## Source : http://tile.stamen.com/terrain/5/3/9.png
## Source : http://tile.stamen.com/terrain/5/4/9.png
## Source : http://tile.stamen.com/terrain/5/1/10.png
## Source : http://tile.stamen.com/terrain/5/2/10.png
## Source : http://tile.stamen.com/terrain/5/3/10.png
## Source : http://tile.stamen.com/terrain/5/4/10.png
ggmap(map1)
ggmap(map1) +
geom_point(data = grizzly, aes(longitude, latitude), size=0.8) +
labs(x = "Longitude", y = "Latitude", title = "Grizzly bears")
Let’s switch to the wolves data. Brandell, Ellen E (2021), Serological dataset and R code for: Patterns and processes of pathogen exposure in gray wolves across North America, Dryad, Dataset.
wolves <- read_csv(here("lab12", "data", "wolves_data", "wolves_dataset.csv"))
## Rows: 1986 Columns: 23
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): pop, age.cat, sex, color
## dbl (19): year, lat, long, habitat, human, pop.density, pack.size, standard....
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
glimpse(wolves)
## Rows: 1,986
## Columns: 23
## $ pop <chr> "AK.PEN", "AK.PEN", "AK.PEN", "AK.PEN", "AK.PEN", "…
## $ year <dbl> 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 200…
## $ age.cat <chr> "S", "S", "A", "S", "A", "A", "A", "P", "S", "P", "…
## $ sex <chr> "F", "M", "F", "M", "M", "M", "F", "M", "F", "M", "…
## $ color <chr> "G", "G", "G", "B", "B", "G", "G", "G", "G", "G", "…
## $ lat <dbl> 57.03983, 57.03983, 57.03983, 57.03983, 57.03983, 5…
## $ long <dbl> -157.8427, -157.8427, -157.8427, -157.8427, -157.84…
## $ habitat <dbl> 254.08, 254.08, 254.08, 254.08, 254.08, 254.08, 254…
## $ human <dbl> 10.42, 10.42, 10.42, 10.42, 10.42, 10.42, 10.42, 10…
## $ pop.density <dbl> 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, …
## $ pack.size <dbl> 8.78, 8.78, 8.78, 8.78, 8.78, 8.78, 8.78, 8.78, 8.7…
## $ standard.habitat <dbl> -1.6339, -1.6339, -1.6339, -1.6339, -1.6339, -1.633…
## $ standard.human <dbl> -0.9784, -0.9784, -0.9784, -0.9784, -0.9784, -0.978…
## $ standard.pop <dbl> -0.6827, -0.6827, -0.6827, -0.6827, -0.6827, -0.682…
## $ standard.packsize <dbl> 1.3157, 1.3157, 1.3157, 1.3157, 1.3157, 1.3157, 1.3…
## $ standard.latitude <dbl> 0.7214, 0.7214, 0.7214, 0.7214, 0.7214, 0.7214, 0.7…
## $ standard.longitude <dbl> -2.1441, -2.1441, -2.1441, -2.1441, -2.1441, -2.144…
## $ cav.binary <dbl> 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
## $ cdv.binary <dbl> 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ cpv.binary <dbl> 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, …
## $ chv.binary <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, …
## $ neo.binary <dbl> NA, NA, NA, 0, 0, NA, NA, 1, 0, 1, NA, 0, NA, NA, N…
## $ toxo.binary <dbl> NA, NA, NA, 1, 0, NA, NA, 1, 0, 0, NA, 0, NA, NA, N…
wolves %>% count(pop)
## # A tibble: 17 × 2
## pop n
## <chr> <int>
## 1 AK.PEN 100
## 2 BAN.JAS 96
## 3 BC 145
## 4 DENALI 154
## 5 ELLES 11
## 6 GTNP 60
## 7 INT.AK 35
## 8 MEXICAN 181
## 9 MI 102
## 10 MT 351
## 11 N.NWT 67
## 12 ONT 60
## 13 SE.AK 10
## 14 SNF 92
## 15 SS.NWT 34
## 16 YNP 383
## 17 YUCH 105
us_wolves <-
wolves %>%
filter(pop %in% c("GTNP", "MEXICAN", "MI", "MT", "SNF", "YNP"))
us_wolves %>%
select(lat, long) %>%
summary()
## lat long
## Min. :33.89 Min. :-110.99
## 1st Qu.:44.60 1st Qu.:-110.99
## Median :44.60 Median :-110.55
## Mean :43.95 Mean :-106.91
## 3rd Qu.:46.83 3rd Qu.:-109.17
## Max. :47.75 Max. : -86.82
lat <- c(33.69, 47.75)
long <- c(-110.99, -86.82)
bbox2 <- make_bbox(long, lat, f = 0.05)
stamen in a terrain-lines projection and display the map.map2 <- get_map(bbox2, maptype = "terrain-lines", source = "stamen")
## Source : http://tile.stamen.com/terrain/5/6/11.png
## Source : http://tile.stamen.com/terrain/5/7/11.png
## Source : http://tile.stamen.com/terrain/5/8/11.png
## Source : http://tile.stamen.com/terrain/5/6/12.png
## Source : http://tile.stamen.com/terrain/5/7/12.png
## Source : http://tile.stamen.com/terrain/5/8/12.png
ggmap(map2)
ggmap(map2) +
geom_point(us_wolves, mapping=aes(x=long, y=lat), size=2)+
labs(x = "Longitude", y = "Latitude", title = "Wolves in the Lower 48")
fill and color by population.ggmap(map2) +
geom_point(us_wolves, mapping=aes(x=long, y=lat, fill=pop, color=pop), size=3)+
labs(x = "Longitude", y = "Latitude", title = "Wolves in the Lower 48")
Please be sure that you check the keep md file in the knit preferences.